package org.crud4j.wicket.markup.html.editor;

import java.util.Date;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.crud4j.core.CrudField;

public class EditorFactory {

	public static Panel getEditor(String name, CrudField field) {
		if (field.getDef().isHidden()) {
			throw new IllegalArgumentException(
					"hidden fields don't have an editor. Field "
							+ field.getDef().getName());
		}

		if (field.getDef().getType().equals(Date.class)) {
			return new DateEditorPanel(name, new DateModel(field));
		}

		IModel model = new PropertyModel(field, "value");
		return new DefaultEditorPanel(name, model);

	}
}
